import { ref } from 'vue';
import { defineStore } from 'pinia';
import Admin from '@/api/admin';
export const useAccountStore = defineStore('account', () => {
    // state--当前账户
    let profile = ref({});

    // actions--加载账户资料
    let loadProfile = async (id) => {
        try {
            let { status, msg, data } = await Admin.info({ id });
            if (status) {
                profile.value = data;
                // console.log(profile.value);
            }
        } catch (error) {
            console.log(error);
        }
    }
    //actions--修改账户资料
    let updateProfile = async (data) => {
        let { status, msg } = await Admin.edit({ ...data });
        if (status) {
            profile.value = { ...data };
            ElMessage.success(msg);
            // router.push('/System/Admin');
        } else {
            ElMessage.error(msg);
        }}
        return {
            profile,
            loadProfile,
            updateProfile
        }
});
